package org.vacoor.ticket.bean.param.impl;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import org.vacoor.ticket.bean.Station;
import org.vacoor.ticket.bean.TimeRegionType;
import org.vacoor.ticket.bean.TrainPassType;
import org.vacoor.ticket.bean.TrainType;
import org.vacoor.ticket.bean.param.Parameter;

/**
 * 封装车票查询条件
 * @author vacoor
 *
 */
public class TicketQueryParam implements Parameter{
	private boolean isStuQuery;		//是否是学生票查询
	private Station fromStation;	//出发站点
	private Station arriveStation;	//目的站点
	private Date trainDate;			//列车日期
	private TimeRegionType timeRegion;	//时间段
	private TrainPassType trainPassType;	//经过类型
	private TrainType[] trainType;		//列车类型
	//
	private String trainNo;				//列车编号,不是车次
//	private String seatTypeAndNum="";  //席别、数量的集合，采用席别#数量@ 可选 //这个在现在好像禁用了 1#2@ 
	
	public TicketQueryParam(Station fromStation,Station arrStation,Date trainDate) {
		this(fromStation,arrStation,trainDate,TimeRegionType.ALL,new TrainType[]{TrainType.ALL});
	}
	
	public TicketQueryParam(Station fromStation,Station arrStation,Date trainDate,TimeRegionType region) {
		this(fromStation,arrStation,trainDate,region,new TrainType[]{TrainType.ALL});
	}
	
	public TicketQueryParam(Station fromStation,Station arrStation,Date trainDate,TimeRegionType region,TrainType[] trainType) {
		this(fromStation,arrStation,trainDate,region,TrainPassType.ALL,trainType);
	}
	
	public TicketQueryParam(Station fromStation,Station arrStation,Date trainDate,TimeRegionType region,TrainPassType passType,TrainType[] trainType) {
		this(false,fromStation,arrStation,trainDate,region,passType,trainType,"");
	}
	
	public TicketQueryParam(boolean isStuQuery,Station fromStation,Station arrStation,Date trainDate,TimeRegionType region,TrainPassType passType,TrainType[] trainType, String trainNo) {
		this.isStuQuery = isStuQuery;
		this.fromStation = fromStation;
		this.arriveStation = arrStation;
		this.trainDate = trainDate;
		this.timeRegion = region;
		this.trainPassType = passType;
		this.trainType = trainType;
		this.trainNo = trainNo;
	}

	@Override
	public String getQueryString() {
		String tmp = "";
		for(TrainType tt : trainType) {
			tmp += tt.getValue();
		}
		return
			//查询字符串
		   "includeStudent=" + (isStuQuery? "0x00" : "00") +		//学生票,0x00为学生 
		   "&orderRequest.from_station_telecode=" + fromStation.getCode() +      //出发站代码
		   "&orderRequest.start_time_str=" + timeRegion.getValue() + 						//时间段// 00:00--24:00
		   "&orderRequest.to_station_telecode=" + arriveStation.getCode() +    //到达站代码
		   "&orderRequest.train_date=" + new SimpleDateFormat("yyyy-MM-dd").format(trainDate) +      //列车日期
		   "&trainPassType=" + trainPassType.getValue() +        //列车过路类型QB,SF,GL
		   //可选
		   "&orderRequest.train_no=" + trainNo +     //列车编号550000L128P0,可选
		   "&trainClass=" + tmp +                   //列车类型D#QB#类似 可选
		   											//QT# 其他
		   											//K# K字头
		   											//T# T字头
		   											//Z# Z字头
		   											//D# 动车
		   											//D#Z# 动车,Z字头车
		   											//QB#D#Z#T#K#QT# 全部
		"&seatTypeAndNum="; 			//席别、数量的集合，采用席别#数量@ 可选 //这个在现在好像禁用了 1#2@
		   											 
	}

	@Override
	public String toString() {
		return "TicketQuery [isStudent=" + isStuQuery + ", fromStation="
				+ fromStation + ", arriveStation=" + arriveStation
				+ ", trainDate=" + trainDate + ", timeRegion=" + timeRegion
				+ ", trainPassType=" + trainPassType + ", trainType="
				+ Arrays.toString(trainType) + ", trainNo=" + trainNo + "]";
	}

	public boolean isStuQuery() {
		return isStuQuery;
	}

	public void setStuQuery(boolean isStuQuery) {
		this.isStuQuery = isStuQuery;
	}

	public Station getFromStation() {
		return fromStation;
	}

	public void setFromStation(Station fromStation) {
		this.fromStation = fromStation;
	}

	public Station getArriveStation() {
		return arriveStation;
	}

	public void setArriveStation(Station arriveStation) {
		this.arriveStation = arriveStation;
	}

	public Date getTrainDate() {
		return trainDate;
	}

	public void setTrainDate(Date trainDate) {
		this.trainDate = trainDate;
	}

	public TimeRegionType getTimeRegion() {
		return timeRegion;
	}

	public void setTimeRegion(TimeRegionType timeRegion) {
		this.timeRegion = timeRegion;
	}

	public TrainPassType getTrainPassType() {
		return trainPassType;
	}

	public void setTrainPassType(TrainPassType trainPassType) {
		this.trainPassType = trainPassType;
	}

	public TrainType[] getTrainType() {
		return trainType;
	}

	public void setTrainType(TrainType[] trainType) {
		this.trainType = trainType;
	}

	public String getTrainNo() {
		return trainNo;
	}

	public void setTrainNo(String trainNo) {
		this.trainNo = trainNo;
	}
	
}
